package com.cn.wxwinnie.java.io;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author 潇湘暮雨 E-mail:wxwinnie@hotmail.com
 * 
 * @version 创建时间：2014年3月25日 下午6:55:49
 * 
 */
public class CharacterFileWR {

	public static char[] readFile(String fpath) throws IOException {
		File f = new File(fpath);
		FileReader fr = new FileReader(f);

		StringBuilder builder = new StringBuilder();
		int c = 0;
		while (true) {
			c = fr.read();
			if (-1 != c)
				builder.append((char) c);
			else
				break;
		}
		fr.close();
		return builder.toString().toCharArray();
	}

	public static void writeFile(String fpath, char[] content)
			throws IOException {
		File f = new File(fpath);
		FileWriter fw = new FileWriter(f, true);//追加文件内容
		fw.write(content);
		fw.close();
	}
}
